package org.shiwen.week8;

public class SuperConstructor {
    private String name;
    private int age;
    private String sex;

    public SuperConstructor(String name, int age, String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public SuperConstructor(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "SuperConstructor{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                '}';
    }
}

class Sub extends SuperConstructor {
    private String school;

    public Sub(String name, int age, String sex, String school) {
        //当需要用到父类的构造方法，需要添加super()，且super()必须放在第一行
        super(name, age, sex);
        this.school = school;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    @Override
    public String toString() {
        return "Sub{" +
                "school='" + school + '\'' +
                //这里重写了toString()方法，但是我们依旧需要用到父类的toString()方法，所以这里需要用到super.toString()
                "} " + super.toString();
    }
}

class Test {
    public static void main(String[] args) {
        Sub s = new Sub("张三", 18, "male", "HUST");
        System.out.println(s.toString());
    }
}